class XORCryptoUtil{
  String _code(String text){
    if(text.isEmpty){
      return "";
    }
    String keyStr = "sds12dkair";
    List textCodeUnits = text.codeUnits;
    List keyCodeUnits = keyStr.codeUnits;
    int len = textCodeUnits.length;
    int keyLen = keyCodeUnits.length;
    List<int> result = List.filled(len, 0);
    for(int i=0;i<len;i++){
      result[i] = textCodeUnits[i]^keyCodeUnits[i%keyLen];
    }
    return String.fromCharCodes(result);
  }
  String encode(String text){
    return _code(text);
  }
  String encodeAndToHex(String text){
    return _textToHex(_code(text));
  }
  String decode(String text){
    return _code(text);
  }
  //字符串转为16进制
  String _textToHex(String text){
    if(text.isEmpty){
      return "";
    }
    List<int> codeUnits = text.codeUnits;
    StringBuffer stringBuffer = StringBuffer();
    for(int i in codeUnits){
      stringBuffer.write(i.toRadixString(16).padLeft(2,"0"));
    }
    return stringBuffer.toString();
  }
}